
#include <glib-2.0/glib.h>
#include <pulse/pulseaudio.h>
#include <pulse/simple.h>

gboolean is_pulseaudio_available(pa_stream_direction_t direction) {
    pa_simple *s;
    int error;
     static const pa_sample_spec ss = {
        .format = PA_SAMPLE_S16LE,
        .rate = 44100,
        .channels = 2
    };
    
    s = pa_simple_new(NULL,               // Use the default server.
                  "TuxInStudio",           // Our application's name.
                  direction,
                  NULL,               // Use the default device.
                  "Test",            // Description of our stream.
                  &ss,                // Our sample format.
                  NULL,               // Use default channel map
                  NULL,               // Use default buffering attributes.
                  &error             
                 );
    if (!s) {
        g_debug("could not open pulseaudio connection: %s",pa_strerror(error));
        return FALSE;
    } else {
        pa_simple_free(s);
        return TRUE;
    }
}

gboolean is_pulseaudio_playback_available() {
    return is_pulseaudio_available(PA_STREAM_PLAYBACK);
}

gboolean is_pulseaudio_record_available() {
    return is_pulseaudio_available(PA_STREAM_RECORD);
}
